﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using LiuYan.Entity;
using LiuYan.Service;


namespace LiuYan.Web.Areas.Admin.Controllers
{
    public class MenuController : BaseController
    {
        //
        // GET: /Admin/Menu/

        public ActionResult Index()
        {
            ViewData["pmenu"] = new MenuService().GetPmenu(UserInfo().RoleId);
            ViewData["pmenu"] = new MenuService().GetPmenu();
            return View();
        }
        public ActionResult Window(int id)
        {
            ViewData["id"] = id;
            ViewData["menu"] = new MenuService().GetPList();
            return View();
        }

        public int Edit(FormCollection form)
        {
            TB_Menu entity=new TB_Menu();
            entity.Id = Convert.ToInt32(form["id"]);
            entity.Del = 0;
            entity.IsLanMu = 0;
            entity.Name = form["name"];
            entity.Url = form["url"];
            entity.Pid = Convert.ToInt32(form["pid"]);
            entity.UserId = UserInfo().Id;
            entity.Date = DateTime.Now;
            entity.Remark = form["remark"];
            entity.Order = Convert.ToInt32(form["order"]);
           return new MenuService().Edit(entity);
        }

        public int Del(int id)
        {
            return new MenuService().Del(id);
        }

        
        public string  GetOneData(int id)
        {
            return JsonConvert.SerializeObject(new BaseService().GetOneData(id, "Tb_menu"));
        }

        public DataTable GetCmenu(int pId)
        {
            return new MenuService().GetCmenu(pId);
        }
    }
}
